{% extends "admin/base.html" %}

{% block title %}成功案例管理 - 管理後台{% endblock %}

{% block page_title %}成功案例管理{% endblock %}

{% block content %}
<div class="card">
    <div class="card-body">
        <div class="d-flex justify-content-between align-items-center mb-4">
            <h5 class="card-title mb-0">成功案例列表</h5>
            <a href="{{ url_for('admin.add_case') }}" class="btn btn-primary">
                <i class="fas fa-plus"></i> 添加案例
            </a>
        </div>

        <div class="table-responsive">
            <table class="table table-hover">
                <thead>
                    <tr>
                        <th>ID</th>
                        <th>中文標題</th>
                        <th>英文標題</th>
                        <th>圖片</th>
                        <th>創建時間</th>
                        <th>操作</th>
                    </tr>
                </thead>
                <tbody>
                    {% for item in cases.items %}
                    <tr>
                        <td>{{ item.id }}</td>
                        <td>{{ item.zh_title }}</td>
                        <td>{{ item.en_title }}</td>
                        <td>
                            {% if item.images %}
                                <img src="{{ item.images.split(',')[0] }}" alt="案例圖片" style="height: 50px;">
                            {% endif %}
                        </td>
                        <td>{{ item.created_at.strftime('%Y-%m-%d %H:%M') }}</td>
                        <td>
                            <div class="btn-group">
                                <a href="{{ url_for('admin.edit_case', case_id=item.id) }}" 
                                   class="btn btn-sm btn-outline-primary">
                                    編輯
                                </a>
                                <form method="POST" 
                                      action="{{ url_for('admin.delete_case', case_id=item.id) }}"
                                      class="d-inline" 
                                      onsubmit="return confirm('確定要刪除這個案例嗎？');">
                                    <button type="submit" class="btn btn-sm btn-outline-danger">刪除</button>
                                </form>
                            </div>
                        </td>
                    </tr>
                    {% endfor %}
                </tbody>
            </table>
        </div>

        <!-- 分页 -->
        {% if cases.pages > 1 %}
        <nav class="mt-4">
            <ul class="pagination justify-content-center">
                <li class="page-item {{ 'disabled' if not cases.has_prev }}">
                    <a class="page-link" href="{{ url_for('admin.cases', page=cases.prev_num) }}">上一頁</a>
                </li>
                {% for page_num in cases.iter_pages(left_edge=2, left_current=2, right_current=3, right_edge=2) %}
                    {% if page_num %}
                        <li class="page-item {{ 'active' if page_num == cases.page }}">
                            <a class="page-link" href="{{ url_for('admin.cases', page=page_num) }}">{{ page_num }}</a>
                        </li>
                    {% else %}
                        <li class="page-item disabled"><span class="page-link">...</span></li>
                    {% endif %}
                {% endfor %}
                <li class="page-item {{ 'disabled' if not cases.has_next }}">
                    <a class="page-link" href="{{ url_for('admin.cases', page=cases.next_num) }}">下一頁</a>
                </li>
            </ul>
        </nav>
        {% endif %}
    </div>
</div>
{% endblock %} 